﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;
namespace MagicBag.CRM.DALFactory
{
    public sealed class DataAccess
    {
        private static readonly string crmPath = ConfigurationManager.AppSettings["CRMDAL"];
        private static readonly string basePath = GetDAlPath("BaseDAL");
        private static readonly string permissionPath = GetDAlPath("PermissionDAL");
        private static readonly string deptPath = GetDAlPath("DeptDAL");
        private static readonly string mailPath = GetDAlPath("MailDAL");
        private static readonly string smsPath = GetDAlPath("SMSDAL");
        private static readonly string faxPath = GetDAlPath("FaxDAL");
        private static readonly string logPath = GetDAlPath("LogDAL");
        private static readonly string fileSharePath = GetDAlPath("FileShareDAL");

        /// <summary>
        /// 获取DAL路径
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string GetDAlPath(string key)
        {
            string path = ConfigurationManager.AppSettings[key];
            return string.IsNullOrEmpty(path) ? crmPath : crmPath;
        }

        public static MagicBag.CRM.IDAL.ICommonDictionary CreateCommonDictionary()
        {
            string className = basePath + ".CommonDictionaryDAL";
            return (MagicBag.CRM.IDAL.ICommonDictionary)Assembly.Load(basePath).CreateInstance(className);
        }

        public static MagicBag.CRM.IDAL.IDepartment CreateDepartment()
        {
            string className = basePath + ".DepartmentDAL";
            return (MagicBag.CRM.IDAL.IDepartment)Assembly.Load(basePath).CreateInstance(className);
        }

        public static MagicBag.CRM.IDAL.IRole CreateRole()
        {
            string className = basePath + ".RoleDAL";
            return (MagicBag.CRM.IDAL.IRole)Assembly.Load(basePath).CreateInstance(className);
        }

        public static MagicBag.CRM.IDAL.IMenu CreateMenu()
        {
            string className = basePath + ".MenuDAL";
            return (MagicBag.CRM.IDAL.IMenu)Assembly.Load(basePath).CreateInstance(className);
        }

        public static MagicBag.CRM.IDAL.IRoleMenu CreateRoleMenu()
        {
            string className = basePath + ".RoleMenuDAL";
            return (MagicBag.CRM.IDAL.IRoleMenu)Assembly.Load(basePath).CreateInstance(className);
        }

    }
}
